﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class View_RepairJobProblems : _View_RepairJobProblems
    {
        public static View_RepairJobProblems GetCurrentJobProblems()
        {
            try
            {
                View_RepairJobProblems jobProb = new View_RepairJobProblems();
                jobProb.Where.StatusID.Value = RepairStatus.Returned;
                jobProb.Where.StatusID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.NotEqual;

                MyGeneration.dOOdads.WhereParameter whereStatusID = jobProb.Where.TearOff.StatusID;
                whereStatusID.Conjuction = MyGeneration.dOOdads.WhereParameter.Conj.Or;
                whereStatusID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.IsNull;

                jobProb.Query.Load();
                return jobProb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetCurrentJobProblems", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairJobProblems GetJobProblemsByNo(string no)
        {
            try
            {
                View_RepairJobProblems jobProb = new View_RepairJobProblems();
                jobProb.Where.RepairNo.Value = no;

                jobProb.Query.Load();
                return jobProb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetJobProblemsByNo", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairJobProblems GetJobProblemsByBrandID(int brandID)
        {
            try
            {
                View_RepairJobProblems jobProb = new View_RepairJobProblems();
                jobProb.Where.BrandID.Value = brandID;

                jobProb.Query.Load();
                return jobProb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetJobProblemsByBrandID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairJobProblems GetJobProblemsByRepairModelID(int modelID)
        {
            try
            {
                View_RepairJobProblems jobProb = new View_RepairJobProblems();
                jobProb.Where.RepairModelID.Value = modelID;

                jobProb.Query.Load();
                return jobProb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetJobProblemsByBrandID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairJobProblems GetJobProblemsByJobID(int jobID)
        {
            try
            {
                View_RepairJobProblems jobProb = new View_RepairJobProblems();
                jobProb.Where.RepairJobID.Value = jobID;

                jobProb.Query.Load();
                return jobProb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetJobProblemsByNo", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairJobProblems GetJobProblemsByIMEI(string imei)
        {
            try
            {
                View_RepairJobProblems jobProb = new View_RepairJobProblems();
                jobProb.Where.IMEI.Value = imei;

                jobProb.Query.Load();
                return jobProb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetCurrentJobProblems", ex.StackTrace);
                throw ex;
            }
        }

        public static View_RepairJobProblems GetDoneOrRejectedJobProblems()
        {
            try
            {
                View_RepairJobProblems jobProb = new View_RepairJobProblems();
                jobProb.Where.StatusID.Value = RepairStatus.Done;

                MyGeneration.dOOdads.WhereParameter whereStatusID = jobProb.Where.TearOff.StatusID;
                whereStatusID.Conjuction = MyGeneration.dOOdads.WhereParameter.Conj.Or;
                whereStatusID.Value = RepairStatus.Rejected;

                jobProb.Query.Load();
                return jobProb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_RepairJobProblems.cs", "GetDoneOrRejectedJobProblems", ex.StackTrace);
                throw ex;
            }
        }
    }
}
